
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module actory</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>actory</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/media/sf_svns/stuff/var/timm/12/python/actory/actory.py">/media/sf_svns/stuff/var/timm/12/python/actory/actory.py</a></font></td></tr></table>
    <p><tt>Actory:&nbsp;a&nbsp;Python-based&nbsp;domain-specific&nbsp;language&nbsp;(DSL)&nbsp;for&nbsp;<br>
specifying&nbsp;finite&nbsp;state&nbsp;machines&nbsp;(FSM).<br>
&nbsp;<br>
Copyright&nbsp;2012,&nbsp;Tim&nbsp;Menzies,&nbsp;tim@menzies.us,<br>
Creative&nbsp;Commons&nbsp;Attribution&nbsp;3.0&nbsp;Unported&nbsp;License.<br>
&nbsp;<br>
Share&nbsp;and&nbsp;enjoy.&nbsp;<br>
:-)<br>
&nbsp;<br>
Todo<br>
====<br>
?</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="random.html">random</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="actory.html#Act">Act</a>
</font></dt><dt><font face="helvetica, arial"><a href="actory.html#Machine">Machine</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="actory.html#Easy">Easy</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="actory.html#State">State</a>
</font></dt><dt><font face="helvetica, arial"><a href="actory.html#World">World</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Act">class <strong>Act</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>An&nbsp;<a href="#Act">Act</a>&nbsp;connects&nbsp;States&nbsp;'here'&nbsp;to&nbsp;'there'.&nbsp;<br>
&nbsp;<br>
All&nbsp;the&nbsp;Acts&nbsp;for&nbsp;one&nbsp;state&nbsp;are&nbsp;explored&nbsp;in&nbsp;an&nbsp;order&nbsp;biased&nbsp;by&nbsp;<br>
'priority'&nbsp;(and&nbsp;higher&nbsp;priority&nbsp;acts&nbsp;get&nbsp;explored&nbsp;first).&nbsp;<br>
&nbsp;<br>
Acts&nbsp;have&nbsp;'gaurds'&nbsp;that&nbsp;check&nbsp;for&nbsp;relevance&nbsp;(default=True).<br>
&nbsp;<br>
Acts&nbsp;have&nbsp;'actions'&nbsp;that&nbsp;fire&nbsp;if&nbsp;the&nbsp;guard&nbsp;is&nbsp;satisfied&nbsp;(default=noop).<br>
If&nbsp;an&nbsp;<a href="#Act">Act</a>&nbsp;fires,&nbsp;then&nbsp;a&nbsp;text&nbsp;'tag'&nbsp;is&nbsp;printed.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Act-__init__"><strong>__init__</strong></a>(self, here, there, tag, priority<font color="#909090">=1</font>, guard<font color="#909090">=True</font>, fx<font color="#909090">=&lt;function noop&gt;</font>)</dt><dd><tt>Constructor.&nbsp;When&nbsp;creating&nbsp;a&nbsp;new&nbsp;<a href="#Act">Act</a>,&nbsp;it&nbsp;is&nbsp;always&nbsp;installed<br>
into&nbsp;the&nbsp;outs&nbsp;list&nbsp;of&nbsp;the&nbsp;'here'&nbsp;state.</tt></dd></dl>

<dl><dt><a name="Act-__repr__"><strong>__repr__</strong></a>(self)</dt><dd><tt>Pretty&nbsp;print&nbsp;an&nbsp;<a href="#Act">Act</a></tt></dd></dl>

<dl><dt><a name="Act-ready"><strong>ready</strong></a>(self)</dt><dd><tt>Check&nbsp;if&nbsp;this&nbsp;<a href="#Act">Act</a>&nbsp;is&nbsp;ready&nbsp;to&nbsp;run.</tt></dd></dl>

<dl><dt><a name="Act-sideEffect"><strong>sideEffect</strong></a>(self)</dt><dd><tt>Fire&nbsp;the&nbsp;side-effect&nbsp;associated&nbsp;with&nbsp;performing&nbsp;this&nbsp;<a href="#Act">Act</a>.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Easy">class <strong>Easy</strong></a>(<a href="actory.html#Machine">Machine</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt><a href="#Easy">Easy</a>&nbsp;is&nbsp;a&nbsp;quick&nbsp;way&nbsp;of&nbsp;creating&nbsp;machines&nbsp;from&nbsp;a&nbsp;string.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="actory.html#Easy">Easy</a></dd>
<dd><a href="actory.html#Machine">Machine</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="Easy-create"><strong>create</strong></a>(self, str)</dt><dd><tt>Parsing&nbsp;the&nbsp;strings.&nbsp;Dirty.</tt></dd></dl>

<dl><dt><a name="Easy-priority"><strong>priority</strong></a>(self, str)</dt><dd><tt>If&nbsp;a&nbsp;line&nbsp;ends&nbsp;in&nbsp;*&nbsp;N,&nbsp;then&nbsp;the&nbsp;priority&nbsp;of&nbsp;that&nbsp;<a href="#Act">Act</a>&nbsp;is&nbsp;N.</tt></dd></dl>

<hr>
Methods inherited from <a href="actory.html#Machine">Machine</a>:<br>
<dl><dt><a name="Easy-__init__"><strong>__init__</strong></a>(self, str<font color="#909090">=''</font>)</dt><dd><tt>Constructor.&nbsp;Machines&nbsp;have&nbsp;a&nbsp;'start'&nbsp;state&nbsp;<br>
and&nbsp;a&nbsp;list&nbsp;of&nbsp;'actions'&nbsp;and&nbsp;'states'.</tt></dd></dl>

<dl><dt><a name="Easy-act"><strong>act</strong></a>(self, before, after, tag, priority<font color="#909090">=1</font>, guard<font color="#909090">=True</font>, fx<font color="#909090">=True</font>)</dt><dd><tt>Add&nbsp;an&nbsp;<a href="#Act">Act</a>&nbsp;to&nbsp;this&nbsp;machine.</tt></dd></dl>

<dl><dt><a name="Easy-run"><strong>run</strong></a>(self, world<font color="#909090">=&lt;actory.World object&gt;</font>, lives<font color="#909090">=3</font>)</dt><dd><tt>Find&nbsp;new&nbsp;Acts&nbsp;that&nbsp;are&nbsp;ready&nbsp;to&nbsp;go&nbsp;and&nbsp;fire&nbsp;them.</tt></dd></dl>

<dl><dt><a name="Easy-state"><strong>state</strong></a>(self, name)</dt><dd><tt>Ensure&nbsp;a&nbsp;state&nbsp;called&nbsp;'name'&nbsp;exists.&nbsp;If&nbsp;this&nbsp;the&nbsp;first&nbsp;state<br>
in&nbsp;this&nbsp;machine,&nbsp;make&nbsp;it&nbsp;the&nbsp;start&nbsp;state.</tt></dd></dl>

<hr>
Data descriptors inherited from <a href="actory.html#Machine">Machine</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Machine">class <strong>Machine</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>A&nbsp;machine&nbsp;holds&nbsp;many&nbsp;Acts.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Machine-__init__"><strong>__init__</strong></a>(self, str<font color="#909090">=''</font>)</dt><dd><tt>Constructor.&nbsp;Machines&nbsp;have&nbsp;a&nbsp;'start'&nbsp;state&nbsp;<br>
and&nbsp;a&nbsp;list&nbsp;of&nbsp;'actions'&nbsp;and&nbsp;'states'.</tt></dd></dl>

<dl><dt><a name="Machine-act"><strong>act</strong></a>(self, before, after, tag, priority<font color="#909090">=1</font>, guard<font color="#909090">=True</font>, fx<font color="#909090">=True</font>)</dt><dd><tt>Add&nbsp;an&nbsp;<a href="#Act">Act</a>&nbsp;to&nbsp;this&nbsp;machine.</tt></dd></dl>

<dl><dt><a name="Machine-create"><strong>create</strong></a>(self)</dt><dd><tt>Build&nbsp;the&nbsp;actions&nbsp;within&nbsp;this&nbsp;machine&nbsp;(implemented&nbsp;by&nbsp;subclasses)</tt></dd></dl>

<dl><dt><a name="Machine-run"><strong>run</strong></a>(self, world<font color="#909090">=&lt;actory.World object&gt;</font>, lives<font color="#909090">=3</font>)</dt><dd><tt>Find&nbsp;new&nbsp;Acts&nbsp;that&nbsp;are&nbsp;ready&nbsp;to&nbsp;go&nbsp;and&nbsp;fire&nbsp;them.</tt></dd></dl>

<dl><dt><a name="Machine-state"><strong>state</strong></a>(self, name)</dt><dd><tt>Ensure&nbsp;a&nbsp;state&nbsp;called&nbsp;'name'&nbsp;exists.&nbsp;If&nbsp;this&nbsp;the&nbsp;first&nbsp;state<br>
in&nbsp;this&nbsp;machine,&nbsp;make&nbsp;it&nbsp;the&nbsp;start&nbsp;state.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="State">class <strong>State</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>A&nbsp;<a href="#State">State</a>&nbsp;is&nbsp;a&nbsp;pause&nbsp;point&nbsp;inside&nbsp;a&nbsp;<a href="#Machine">Machine</a>.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="State-__init__"><strong>__init__</strong></a>(self, name)</dt><dd><tt>States&nbsp;have&nbsp;a&nbsp;text&nbsp;'name'&nbsp;and&nbsp;list&nbsp;of&nbsp;'outs'&nbsp;Acts.&nbsp;For&nbsp;effeciency<br>
reasons,&nbsp;this&nbsp;list&nbsp;is&nbsp;sorted&nbsp;decreasing&nbsp;on&nbsp;<a href="#Act">Act</a>&nbsp;priority&nbsp;order.<br>
The&nbsp;sum&nbsp;of&nbsp;all&nbsp;<a href="#Act">Act</a>&nbsp;priorities&nbsp;in&nbsp;'outs'&nbsp;is&nbsp;'totalProbs'.</tt></dd></dl>

<dl><dt><a name="State-__repr__"><strong>__repr__</strong></a>(self)</dt><dd><tt>Pretty&nbsp;print&nbsp;this&nbsp;<a href="__builtin__.html#object">object</a>.</tt></dd></dl>

<dl><dt><a name="State-flags"><strong>flags</strong></a>(self, name)</dt><dd><tt>States&nbsp;have&nbsp;flags&nbsp;'isEndState',&nbsp;'isErrorState',&nbsp;'isProgressState'.<br>
These&nbsp;are&nbsp;set&nbsp;from&nbsp;special&nbsp;symbols&nbsp;in&nbsp;the&nbsp;state&nbsp;name.</tt></dd></dl>

<dl><dt><a name="State-goOn"><strong>goOn</strong></a>(self, act, w)</dt><dd><tt>Returns&nbsp;false&nbsp;if&nbsp;we&nbsp;are&nbsp;at&nbsp;error&nbsp;or&nbsp;end&nbsp;state,&nbsp;or&nbsp;if&nbsp;we&nbsp;are&nbsp;looping.</tt></dd></dl>

<dl><dt><a name="State-looping"><strong>looping</strong></a>(self, n)</dt><dd><tt>We&nbsp;are&nbsp;looping&nbsp;if&nbsp;this&nbsp;is&nbsp;not&nbsp;a&nbsp;progress&nbsp;cycle&nbsp;and&nbsp;we've&nbsp;been&nbsp;here&nbsp;before.</tt></dd></dl>

<dl><dt><a name="State-onEntry"><strong>onEntry</strong></a>(self, act, w)</dt><dd><tt>On&nbsp;entry&nbsp;to&nbsp;a&nbsp;state,&nbsp;do&nbsp;something.</tt></dd></dl>

<dl><dt><a name="State-onExit"><strong>onExit</strong></a>(self, act, w)</dt><dd><tt>On&nbsp;exit&nbsp;from&nbsp;a&nbsp;state,&nbsp;do&nbsp;something.</tt></dd></dl>

<dl><dt><a name="State-out"><strong>out</strong></a>(self, act)</dt><dd><tt>When&nbsp;we&nbsp;add&nbsp;an&nbsp;act&nbsp;to&nbsp;'outs',&nbsp;we&nbsp;update&nbsp;'totalProb'&nbsp;and&nbsp;re-sort.</tt></dd></dl>

<dl><dt><a name="State-todo"><strong>todo</strong></a>(self, lives)</dt><dd><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Search&nbsp;'outs'&nbsp;for&nbsp;an&nbsp;<a href="#Act">Act</a>&nbsp;that&nbsp;is&nbsp;ready&nbsp;to&nbsp;fire.&nbsp;This&nbsp;search&nbsp;is<br>
biased&nbsp;by&nbsp;<a href="#Act">Act</a>&nbsp;priorities.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="World">class <strong>World</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>A&nbsp;<a href="#World">World</a>&nbsp;is&nbsp;the&nbsp;working&nbsp;memory&nbsp;passed&nbsp;around&nbsp;the&nbsp;inference.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="World-__init__"><strong>__init__</strong></a>(self)</dt></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-egs"><strong>egs</strong></a>(*lst)</dt><dd><tt>Simple&nbsp;regression&nbsp;tool:&nbsp;runs&nbsp;all&nbsp;the&nbsp;functions&nbsp;in&nbsp;'lst'.</tt></dd></dl>
 <dl><dt><a name="-inc"><strong>inc</strong></a>(d, key, delta<font color="#909090">=1</font>)</dt><dd><tt>Increment&nbsp;a&nbsp;counter&nbsp;at&nbsp;key[d].</tt></dd></dl>
 <dl><dt><a name="-lstrips"><strong>lstrips</strong></a>(lst)</dt></dl>
 <dl><dt><a name="-noop"><strong>noop</strong></a>(*lst)</dt><dd><tt>Input&nbsp;any&nbsp;number&nbsp;of&nbsp;arguments&nbsp;and&nbsp;nothing.</tt></dd></dl>
 <dl><dt><a name="-often"><strong>often</strong></a>(seq, total, item, weight)</dt><dd><tt>Iterator.&nbsp;Selects&nbsp;with&nbsp;some&nbsp;bias&nbsp;from&nbsp;a&nbsp;sequence&nbsp;of&nbsp;items&nbsp;x.<br>
'Item'&nbsp;and&nbsp;'weight'&nbsp;are&nbsp;lambda&nbsp;bodies.<br>
Each&nbsp;item(x)&nbsp;contributes&nbsp;weight(x)&nbsp;to&nbsp;a&nbsp;'total'&nbsp;probability.<br>
The&nbsp;sum&nbsp;of&nbsp;all&nbsp;contributions&nbsp;is&nbsp;'total'.</tt></dd></dl>
 <dl><dt><a name="-val"><strong>val</strong></a>(x)</dt><dd><tt>Return&nbsp;a&nbsp;value;&nbsp;if&nbsp;passed&nbsp;a&nbsp;lambda,&nbsp;then&nbsp;run&nbsp;it.</tt></dd></dl>
</td></tr></table>
</body></html>